﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using AutoMapper;
using JRFinances.ViewModels;
using JRFinances.Models;
using JRFinances.ViewModels.RealTransactions;
using JRFinances.ViewModels.Companies;
using JRFinances.ViewModels.Reviews;
using JRFinances.ViewModels.VirtualTransactions;
using JRFinances.ViewModels.Groups;

namespace JRFinances.Business
{
    public class AutoMapperManager
    {
        public static void Configure()
        {
            #region Companies

            Mapper.CreateMap<Company, IndexCompanyViewModel>();
            Mapper.CreateMap<Company, DetailsCompanyViewModel>()
                .ForMember(x => x.NumberOfRealBuyTransactions, y => y.Ignore());

            #endregion

            #region RealTransacions

            Mapper.CreateMap<CreateRealTransactionViewModel, RealTransaction>()
                .ForMember(x => x.ChangeTracker, y => y.Ignore())
                .ForMember(x => x.UserId, y => y.Ignore())
                .ForMember(x => x.User, y => y.Ignore())
                .ForMember(x => x.Groups, y => y.Ignore())
                .ForMember(x => x.TransactionId, y => y.Ignore())
                .ForMember(x => x.UserId, y => y.Ignore())
                .ForMember(x => x.Company, y => y.Ignore())
                .ForMember(x => x.CommentsRealTransactions, y => y.Ignore());

            Mapper.CreateMap<RealTransaction, RealTransactionsHistoryViewModel>()
                .ForMember(x => x.CompanyName, y => y.ResolveUsing(z => z.Company.Name));

            Mapper.CreateMap<SellRealTransactionViewModel, RealTransaction>()
                .ForMember(x => x.ChangeTracker, y => y.Ignore())
                .ForMember(x => x.UserId, y => y.Ignore())
                .ForMember(x => x.User, y => y.Ignore())
                .ForMember(x => x.Groups, y => y.Ignore())
                .ForMember(x => x.TransactionId, y => y.Ignore())
                .ForMember(x => x.UserId, y => y.Ignore())
                .ForMember(x => x.Company, y => y.Ignore())
                .ForMember(x => x.CommentsRealTransactions, y => y.Ignore())
                .ForMember(x => x.Buy, y => y.Ignore())
                .ForMember(x => x.CompanyId, y => y.Ignore());

            #endregion

            #region Reviews

            Mapper.CreateMap<Review, IndexReviewViewModel>()
                .ForMember(x => x.User, y => y.ResolveUsing(z => z.User.Name))
                .ForMember(x => x.Date, y => y.ResolveUsing(z => z.Date));

            Mapper.CreateMap<CreateReviewViewModel, Review>()
                .ForMember(x => x.ChangeTracker, y => y.Ignore())
                .ForMember(x => x.UserId, y => y.Ignore())
                .ForMember(x => x.CommentsReviews, y => y.Ignore())
                .ForMember(x => x.Groups, y => y.Ignore())
                .ForMember(x => x.User, y => y.Ignore())
                .ForMember(x => x.UserId, y => y.Ignore())
                .ForMember(x => x.ReviewId, y => y.Ignore())
                .ForMember(x => x.Companies, y => y.Ignore());

            Mapper.CreateMap<Review, DetailsReviewViewModel>()
                .ForMember(x => x.User, y => y.ResolveUsing(z => z.User.Name));

            Mapper.CreateMap<Review, ManageOwnedReviewsViewModel>();

            #endregion

            #region VirtualTransacions

            Mapper.CreateMap<CreateVirtualTransactionViewModel, VirtualTransaction>()
                .ForMember(x => x.ChangeTracker, y => y.Ignore())
                .ForMember(x => x.UserId, y => y.Ignore())
                .ForMember(x => x.User, y => y.Ignore())
                .ForMember(x => x.Groups, y => y.Ignore())
                .ForMember(x => x.TransactionId, y => y.Ignore())
                .ForMember(x => x.UserId, y => y.Ignore())
                .ForMember(x => x.Company, y => y.Ignore())
                .ForMember(x => x.CommentsVirtualTransactions, y => y.Ignore());

            Mapper.CreateMap<VirtualTransaction, VirtualTransactionsHistoryViewModel>()
                .ForMember(x => x.CompanyName, y => y.ResolveUsing(z => z.Company.Name));

            Mapper.CreateMap<SellVirtualTransactionViewModel, VirtualTransaction>()
                .ForMember(x => x.ChangeTracker, y => y.Ignore())
                .ForMember(x => x.UserId, y => y.Ignore())
                .ForMember(x => x.User, y => y.Ignore())
                .ForMember(x => x.Groups, y => y.Ignore())
                .ForMember(x => x.TransactionId, y => y.Ignore())
                .ForMember(x => x.UserId, y => y.Ignore())
                .ForMember(x => x.Company, y => y.Ignore())
                .ForMember(x => x.CommentsVirtualTransactions, y => y.Ignore())
                .ForMember(x => x.Buy, y => y.Ignore())
                .ForMember(x => x.CompanyId, y => y.Ignore());

            #endregion

            #region Groups

            Mapper.CreateMap<Group, IndexGroupViewModel>();

            Mapper.CreateMap<Group, ManageOwnedGroupsViewModel>();

            Mapper.CreateMap<Group, DetailsGroupViewModel>()
                .ForMember(x => x.UserNames, y => y.Ignore());

            Mapper.CreateMap<Group, ManageGroupUsersViewModel>()
                .ForMember(x => x.Activated, y => y.Ignore())
                .ForMember(x => x.NotActivated, y => y.Ignore());

            #endregion
        }
    }
}